#size
res<-300
width<-500*res/72
height<-4/5*width

color<-c('gray90','gray30','gray70', 'gray10', 'gray50')
space<-c(0,2)#spaces between pairs of bars
border<-T
lwd_border<-0.5

#grid
lwd_grid<-0.5
color_grid<-"black"

#Data

mydata <- read.csv("data/Covidrisk_wave1.csv", header=T)

percent.self <- mean(mydata$selfCovid)*100
percent.family <- mean(mydata$familyCovid)*100
percent.friend <- mean(mydata$friendCovid)*100
percent.coworker <- mean(mydata$coworkerCovid)*100
percent.none <- mean(mydata$noCovid)*100

covid<-c(percent.self,percent.family,percent.friend,percent.coworker,percent.none)
 
#Export to tiff
tiff(filename = "figures_tables/Figure2.tif",
     width = width, 
     height =height,
     res=res,
     units = "px", 
     pointsize=9,
     bg = "white", 
     type = 'cairo')

par(mar=c(4,6,3,4)+0.1,lwd=lwd_border)

barplot(rbind(covid), width=0.3, xlim=c(0,3.5), ylim=c(0,60),beside=T,
        col=color,,space=c(0.75,.75,.75,.75, .75))
        
abline(h=seq(0,60,5),col=color_grid,lwd=lwd_grid)
abline(h=0)
abline(h=60)

mtext(c('Self', 'Family', 'Friend', 'Coworker', 'None'),side=1,line=2,at=c(0.25,0.8,1.35,1.9, 2.45)+0.1)

barplot(rbind(covid), width=0.3, xlim=c(0,3.5), ylim=c(0,60),beside=T,
        col=color,lwd=lwd_border,space=c(0.75,.75,.75,.75, .75),
        ylab='Percentage of respondents',add=T)

dev.off()